/*
 * Description: performance lifecycle handler
 */
#ifndef PERF_LIFECYCLE_HANDLER_H
#define PERF_LIFECYCLE_HANDLER_H
#include <vector>
#include <memory>
#include "error.h"
#include "log.h"
#include "singleton.h"
#include "rpc_service/sendto_host.h"
#include "performance/model/perf_info.h"
#include "performance/accelerator/base/perf_accelerator.h"

namespace PERF {
class PerfLifeCycleHandler {
public:
    bool Init(std::shared_ptr<WINCONTROL::SendToHost> sendtoHost);
    void Start(std::shared_ptr<PerfInfo> perfInfo);

private:
    void Prepare(std::shared_ptr<PerfInfo> perfInfo);
    void OnProcessInitStart(std::shared_ptr<PerfInfo> perfInfo);
    void OnProcessInitEnd(std::shared_ptr<PerfInfo> perfInfo);
    void WaitProcessLoad(std::shared_ptr<PerfInfo> perfInfo);
    bool TryFetchProcessLoadStatus(std::shared_ptr<PerfInfo> perfInfo);
    std::vector<std::wstring> FetchWndTexts(const std::wstring &wndTextSuffix);
    bool CouldFetchLoadStatusFromWndText(const std::string &pname);

    std::vector<std::shared_ptr<PerfAccelerator>> accelerators;
    bool StartProcessPreload(std::shared_ptr<PerfInfo> perfInfo);
};
#define PERF_LIFECYCLE_HANDLER SingletonNew<PERF::PerfLifeCycleHandler>::GetInstance()
}  // namespace PERF

#endif